// API服务类
class ApiService {
  constructor() {
    this.baseUrl = 'https://aistore.chasingbrilliant.com';
    // this.baseUrl = 'http://localhost:5002';
  }

  // 上传商户数据
  async uploadMerchantData(data) {
    try {
      const formData = new FormData();
      formData.append('merchant_id', data.merchantId);
      formData.append('platform_type', data.platformType);
      formData.append('merchant_name', data.merchantName);
      formData.append('data_period', data.dataPeriod);
      formData.append('json_data', JSON.stringify(data.jsonData));

      const response = await fetch(`${this.baseUrl}/api/data/upload`, {
        method: 'POST',
        body: formData
      });

      const result = await response.json();
      if (result.code === 200) {
        return {
          success: true,
          data: result.data
        };
      } else {
        return {
          success: false,
          error: result.message
        };
      }
    } catch (error) {
      return {
        success: false,
        error: error.message
      };
    }
  }

  // 复制错误信息到剪贴板
  async copyErrorToClipboard(errorMsg) {
    try {
      await navigator.clipboard.writeText(errorMsg);
      return true;
    } catch (error) {
      console.error('复制错误信息失败:', error);
      return false;
    }
  }
}

// 导出单例实例
export const apiService = new ApiService(); 